package ranab.jar;

import java.util.zip.ZipEntry;

/**
 * Compare two zip entries based on the file name.
 * 
 * @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
 */
public
class ZipSizeComparator extends ZipComparator  {
    
    public int compare(Object o1, Object o2)  {
        if (!(o1 instanceof java.util.zip.ZipEntry && o1 instanceof java.util.zip.ZipEntry))  {
            throw new IllegalArgumentException("Not a ZipEntry object."); 
        }
        
        ZipEntry z1 = (ZipEntry)o1;
        ZipEntry z2 = (ZipEntry)o2;
        long diff =  z1.getSize() - z2.getSize();
        
        if (diff < 0)  {
            return -1;
        }
        else if (diff > 0)  {
            return 1;
        }
        return 0;
    }
    
    public boolean equals(Object o1, Object o2)  {
        if (!(o1 instanceof java.util.zip.ZipEntry && o1 instanceof java.util.zip.ZipEntry))  {
            throw new IllegalArgumentException("Not a ZipEntry object."); 
        }
        
        ZipEntry z1 = (ZipEntry)o1;
        ZipEntry z2 = (ZipEntry)o2;
        return z1.getSize() == z2.getSize();
    }
    
    /**
     * get header name
     */
     public String getHeaderName()  {
         return "Size";
     }
}
